<?php

namespace App;

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;

class Users extends Model
{
	//定义一个属性
	protected $table = 'user';

	//注册邮箱
    public function getAdd($request)
    {
    	$this->name = $request['name'];
    	$this->pwd = md5($request['pwd']);
    	return $this->save();
    }

    // 登录账号
    public function getLogin($request)
    {
    	$data['name'] = $request['name'];
    	$data['pwd'] = md5($request['pwd']);
    	return DB::table('user')->insertGetId($data);
    }

    //发送邮箱
    public function getEmail($request)
    {
    	$id = $request;
    	return DB::table('user')
				->where('id','=',$id)
				->select();
    }
    
    //绑定邮箱
    public function getEmails($request)
    {
    	$id = $request['id'];
    	$email = $request['email'];
    	$flight = self::find($id);

		$flight->email = $email;

		return $flight->save();
    }

    //展示
    public function getShow()
    {
    	return DB::table('user')
            ->join('student', 'user.uid', '=', 'student.uid')
            ->select('user.*', 'student.uid', 'student.uname')
            ->get();
    }

    //赠送积分
    public function getOne($request)
    {
    	$id = $request['id'];
    	return self::find($id);
    }

    //赠送积分
    public function getUpdate($request)
    {
    	$id = $request['id'];
    	$data['name'] = $request['name'];
		$number = $request['number'];
    	$flight = self::find($id);

		$flight->number = ($flight->number)+$number;

		return $flight->save();
    }

    //获取个人积分
    public function getNumOne($request)
    {
    	$id = $request;

    	return self::find($id);

    }

}
